package beer.zivelin.awesome.walawala.mobile.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import beer.zivelin.awesome.walawala.mobile.Tester;

public class ApplicationAddOrRemoveReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {
            String packageName = intent.getDataString();
            Log.d(Tester.TAG, packageName + " installed");
            Toast.makeText(context, packageName + " installed", Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED)) {
            String packageName = intent.getDataString();
            Log.d(Tester.TAG, packageName + " uninstalled");
            Toast.makeText(context, packageName + " uninstalled", Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) {
            String packageName = intent.getDataString();
            Log.d(Tester.TAG, packageName + " reinstalled");
            Toast.makeText(context, packageName + " reinstalled", Toast.LENGTH_LONG).show();
        }

    }


}
